import { Injectable } from '@angular/core';
import { StateMachineService } from "@farris/command-services";
import { FrameContext } from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { FormMessageService, FormNotifyService, CommandService, FormLoadingService, BeActionService } from '@farris/command-services';
import { EMPTY, of } from 'rxjs';
import { tap, map, switchMap } from 'rxjs/operators';

@Injectable()
export class BjrkFormFrmControllerService {
  constructor(
    private frameContext: FrameContext,
    private messageService: FormMessageService,
    private beActionService: BeActionService,
    public stateMachineService: StateMachineService,
    public formNotifyService: FormNotifyService,
    private commandService: CommandService,
    public loadingService: FormLoadingService
  ) { }

  /**
   * 添加数据
   * @remarks 
   * @returns 
   */
  addDatas(): any {
    const context = this.frameContext;
    let id = context.bindingData.getValue(['id'])
    const rep = this.frameContext.repository as BefRepository<any>;
    const datas = this.frameContext.uiState['datas'];
    let tzDadas = []
    debugger
    for (let item of datas) {
      const gcbh = item.data.gcbh
      const wlbh = item.data.wlbh
      const wlmc = item.data.wlmc
      const wlgg = item.data.wlgg
      const wlxh = item.data.wlxh
      const wlcz = item.data.wlcz
      const dw = item.data.dw
      const wzlxid = item.data.wzlxid.wzlxid
      const lbmc = item.data.wzlxid.wzlxid_lbmc
      const ck = item.data.ck
      const jsgg = item.data.jsgg
      const cjs = item.data.cjs
      const zlbxsx = item.data.zlbxsx
      const iszn = item.data.iszn
      const jysyfx = item.data.jysyfx
      const glbm = item.data.glbm.glbm
      const glbmName = item.data.glbm.glbm_name
      tzDadas.push({
        gcbh: gcbh,
        wlbh: wlbh,
        wlmc: wlmc,
        wlgg: wlgg,
        wlxh: wlxh,
        wlcz: wlcz,
        dw: dw,
        wzlxid: {
          wzlxid_lbmc: lbmc
        },
        ck: ck,
        jsgg: jsgg,
        cjs: cjs,
        zlbxsx: zlbxsx,
        iszn: iszn,
        jysyfx: jysyfx,
        glbm: {
          glbm_name: glbmName
        }
      })
    }
    rep.batchAppendByPath('/' + id + '/rkmxs', tzDadas).subscribe()
  }
}
